<?php

	include('Conexion.php');
	$padre = $_COOKIE['id'];
	
	//Conexion a la base de datos
	$con = mysql_connect($GLOBALS["server"],$GLOBALS["host"],$GLOBALS["pass"]) or die ('Ocurri&oacute; el siguiente error en la conexi&oacute;n: ' . mysql_error());
	mysql_query ("SET NAMES 'utf8'");
	mysql_select_db($GLOBALS["database"],$con) or die('Por el momento Pixyd no est&aacute; disponible: ' . mysql_error());

/*session_start();
print $_SESSION['sesion'];
if (isset($_SESSION['tipoSesion'])) {
	//print $_SESSION['tipoSesion'];
}else{
	//header('Location: http://localhost/Pixid/Login.php');
}*/
if (isset($_POST['btn-submit'])) {
	$name = $_POST['field-name'];
	$lastName = $_POST['field-lastName'];
	$sex = $_POST['radio-sex'];
	$cell = $_POST['field-cell'];
	$mail = $_POST['field-mail'];
	$pwd = $_POST['field-pwd'];
	$repwd = $_POST['field-repwd'];
	$entrar = true;
	
if(isset($_POST['btn-submit'])){
	if($name == "") $entrar = false; 
	if($lastName == "") $entrar = false; 
	if($cell == "") $entrar = false; 
	if($mail == "") $entrar = false; 
	if($pwd == "") $entrar = false; 
	if($repwd == "") $entrar = false; 
	if($pwd != $repwd) $entrar = false; 
	
	if($entrar){
		mysql_query("UPDATE Padre SET Padre_Nombre='".$name."', Padre_Apell='".$lastName."', Padre_Sexo='".$sex."', Padre_Celular='".$cell."',Padre_Email='".$mail."', Padre_Pass='".$pwd."' WHERE Padre_ID='".$padre."'", $con) or die("MySQL Login Error: ".mysql_error());
		}
	}
	mysql_close();
}
?>
<h1>Datos del usuario</h1>
<form id="form1" action="PerfilPadre.php" method="post">
<?php

$resultado = mysql_query("SELECT Padre_Nombre, Padre_Apell, Padre_Sexo, Padre_Celular, Padre_Email, Padre_Pass FROM Padre WHERE Padre_ID = ".$padre."", $con) or die("MySQL Login Error: ".mysql_error());
	
	$row = mysql_fetch_array($resultado);
	$name = $row["0"];
	$lastName = $row["1"];
	$sex = $row["2"];
	$cell = $row["3"];
	$mail = $row["4"];
	$pwd = $row["5"];
?>
<label for="field-name">Nombre(s):</label>
<input type="text" id="field-name" name="field-name" value="<?php echo $name ?>"/>
<span name="field-name-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-name'] == "") echo "Favor de ingresar Nombre." ?></span>
<br />
<label for="field-lastName">Apellido(s):</label>
<input type="text" id="field-lastName" name="field-lastName" value="<?php echo $lastName ?>"/>
<span name="field-lastName-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-lastName'] == "") echo "Favor de ingresar Apellido." ?></span>
<br />
<fieldset><legend>Sexo</legend>
<?php
	if($sex == "M"){
?>
<input type="radio" id="radio-sex" name="radio-sex" value="M" checked/> Hombre
<input type="radio" id="radio-sex" name="radio-sex" value="F"/> Mujer
<br />
<?php
	} else {
?>
<input type="radio" id="radio-sex" name="radio-sex" value="M"/> Hombre
<input type="radio" id="radio-sex" name="radio-sex" value="F"checked/> Mujer
<br />
<?php
	} 
?>
</fieldset>
<label for="field-cell">Celular:</label>
<input type="text" id="field-cell" name="field-cell" value="<?php echo $cell ?>"/>
<span name="field-cell-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-cell'] == "") echo "Favor de ingresar su celular." ?></span>
<br />
<label for="field-mail">Correo Electr&oacute;nico:</label>
<input type="text" id="field-mail" name="field-mail" value="<?php echo $mail ?>"/>
<span name="field-mail-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-mail'] == "") echo "Favor de ingresar su correo." ?></span>
<br />
<label for="field-pwd">Contrase&ntilde;a:</label>
<input type="password" id="field-pwd" name="field-pwd" value="<?php echo $pwd ?>"/>
<span name="field-pwd-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-pwd'] == "") echo "Favor de ingresar su contrase&ntilde;a." ?></span>
<br />
<label for="field-pwd">Reescribir Contrase&ntilde;a:</label>
<input type="password" id="field-repwd" name="field-repwd" value="<?php echo $pwd ?>"/>
<span name="field-pwd-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-repwd'] == "") echo "Favor de volver a escribir su contrase&ntilde;a."; if(isset($_POST['btn-submit']) and $_POST['field-pwd'] != $_POST['field-repwd']) echo "Favor de volver a escribir su contrase&ntilde;a.";?></span>
<br />
<input type="submit" id="btn-submit" name="btn-submit" value="Actualizar"/>
<div class="clear"></div>
</form>
